package com.ziki.test.ota.mo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Calendar;

import com.ziki.test.proxool.PoolTest;

public class MoInsert {

    /**
     * @param args
     */
    public static void main(String[] args) {
        PoolTest pool = PoolTest.getInstance();
        Connection conn = null;
        try {
            conn = pool.getConnection();
            conn.setAutoCommit(false);
            PreparedStatement ps = conn.prepareStatement("insert into usr_sms_up "
                    + "(su_mobile, su_content, su_gw_id, su_spnumber, su_group_id) "
                    + "values (?, '1#01028200', '11', '22', 'GROUP1012770093616560')");
            long mobile = 15900000000L;
            System.out.println("start:" + Calendar.getInstance().toString());

            for (int i = 1; i <= 1000; i++) {
                int parameterIndex = 1;
                ps.setString(parameterIndex++, String.valueOf(mobile + i));
                ps.addBatch();
                try {
                    // 每100条提交一次，然后停3秒
                    if (i % 100 == 0) {
                        ps.executeBatch();
                        conn.commit();
                        Thread.sleep(3000L);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            ps.executeBatch();
            ps.close();
            conn.commit();
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            e.printStackTrace();
        } finally {
            System.out.println("end:" + Calendar.getInstance().toString());
            try {
                if (conn != null)
                    conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

}
